import TableHead from './THead'
import TableBody from './TBody'
import { PropertyContext } from '../index'
import React, { useContext } from 'react';

import type { PropertyContextType } from '../type'
import type {BaseTableProps} from './type'

const BaseTable: React.FC = () => {
  const { tableData, tableColumn,customsetData } = useContext(PropertyContext) as PropertyContextType & { setData: Function }

  const handleRowClick:BaseTableProps['onRowClick'] = async ({row}) => {
    await customsetData('currentSelectProperty',row)
    customsetData('detailVisible',true)
  }
 
  return (
    <table className="border-collapse table-auto w-full text-sm">
      <TableHead colums={tableColumn as []}></TableHead>
      <TableBody colums={tableColumn as []} data={tableData as []} onRowClick={handleRowClick}></TableBody>
    </table>
  )
}

export default BaseTable